<%- include('css') %>
<div id="app" style="width:980px">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>类别详情</legend>
    </fieldset>

    <form class="layui-form layui-form-pane" action="" lay-filter="form">

        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input type="number" name="num" lay-verify="required" placeholder="请输入类别序号" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="请输入类别名称" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">封面图</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <!--<button type="button" class="layui-btn" id="headpic" >上传图片</button>-->
                    <div class="layui-upload-list">
                        <img v-if="haspic" style="width: 92px; height: 92px; margin: 0 10px 10px 0;" id="headpreview"
                            v-bind:src="pic">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" v-on:click="doclose" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>

<%- include('script') %>

<script>
    var vm = new Vue({
        el: '#app',
        data:function(){
            return {
                isButtonDisabled:false,
                pic:"",
                haspic:false,
                id:'<%=id%>',
                // load:false
            }
        },
        mounted:function(){
            var self = this;
            layui.use(['form', 'upload'], function () {
                var form = layui.form;
                var upload = layui.upload;

                var load_1 = layer.load()
                $.ajax({
                    url:'/admin/type/'+self.id,
                    type:'GET',
                    data:{},
                    success:(res)=>{
                        if(res.code === 200){
                            // let inter = setInterval(()=>{
                            //     if(self.load){
                                    form.val("form",res.data);
                                    self.haspic = true;
                                    self.pic = res.data.pic;
                                    // clearInterval(inter);
                                    layer.close(load_1);
                                // }
                            // },1000)
                        }else{
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.layer.msg('获取数据失败：'+res.error+' -- '+res.code,{icon:2});
                        }
                    },
                    fail:()=>{
                        layer.close(l);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.layer.msg('请求获取数据失败',{icon:2});
                    }
                });

            });
        },
        methods:{
            doclose:function(){
                parent.vm.iframeclose();
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        }
    })
</script>
